package view
{
	import flash.utils.Dictionary;
	
	import mx.collections.XMLListCollection;
	
	
	public class ObjectXMLMapper {
		private var idToObjectDictionary:Dictionary = new Dictionary();
		private var objectToIdDictionary:Dictionary = new Dictionary();
//		private var xmlDictionary:XML = new XML("<xml/>");
		
		public function ObjectXMLMapper() {
		}
		
		public function addObject(object:Object, xml:XML):void {
			var xmlId:String = xml.@id;
			this.idToObjectDictionary[xmlId] = object;
			this.objectToIdDictionary[object] = xmlId;
//			xmlDictionary.appendChild(xml.copy());
			debugTrace(); 
		}
		
		public function isInObjects(xml:XML):Object {
			var xmlId:String = xml.@id;
			return this.idToObjectDictionary[xmlId];
		}
		/**
		 * 現在のオブジェクト辞書にあるアイテムから，削除されたアイテムを探します．
		 */    	
    	private function checkDeletedItems(xmlListCollection:XMLListCollection):Array {
    		var copy:Dictionary = new Dictionary();
    		for(var key:String in this.idToObjectDictionary) {
    			copy[key] = this.idToObjectDictionary[key];
    		} 
    		// xmlListCollectionにある
    		/*
    		for(var xml:XML in xmlListCollection) {
    			var xmlId:String = xml.@id;
    			if(copy[xmlId]) { 
    				
    			}
    		}
    		*/
    		/*
    		// XMLのリストの中にないオブジェクトを探します
    		var deletedItems:Array = new Array();
       		for each(var entityInDictionary:EntityIcon in this.idToObjectDictionary) {
       			var entityId:String = entityInDictionary.entity.@id;
//     			trace(targetXML.entity.(@id == entityId).toXMLString());
       			if(targetXML.entity.(@id == entityId).length() == 0) {
   					deletedItems.push(entityInDictionary);
       			}
       		}
       		*/
       		
    		//return deletedItems;
    		return null;
    	}
    			
		public function objects():Dictionary {
			return this.idToObjectDictionary;
		}
		
		private function debugTrace():void {
			trace(this);
			for each(var object:Object in this.idToObjectDictionary) {
				trace("object=", object);
			}
			for each(var id:String in this.objectToIdDictionary) {
				trace("id=", id);
			}
		}
	}
}